package sunstar.com.xq.presenter

import cn.bmob.v3.BmobQuery
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.FindListener
import sunstar.com.xq.databean.CardData
import sunstar.com.xq.view.RecycleAdapterView

/**
 * Created by Sun.Star on 2017/6/20.
 */
class TimeLinePresent (var recycleAdapterView: RecycleAdapterView,var list: MutableList<CardData>){
    var pageIndex = 1
    fun loadMore(userId: String){
        pageIndex+=1
        getData(userId)
    }
    fun getData(userId: String){
        BmobQuery<CardData>().addWhereEqualTo("userId",userId).setLimit(20).findObjects(object : FindListener<CardData>(){
            override fun done(p0: MutableList<CardData>?, p1: BmobException?) {
                if(pageIndex == 1){
                    list.clear()
                }
                list!!.addAll(p0!!)
                recycleAdapterView.refreshData()
            }
        })
    }
    fun reLoad(userId: String){
        pageIndex = 1
        getData(userId)
    }
}